package com.albaba.designpattern.singleton;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: TODO
 * @Author zx
 * @Date 2025/2/18 16:46
 * @Version 1.0
 */
public class Test_Singleton_003 {

    static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
            5, 10, 30, TimeUnit.MINUTES, new LinkedBlockingQueue<>(),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName("thread-" + r.hashCode());
                    return thread;
                }
            },
            new ThreadPoolExecutor.DiscardOldestPolicy()
    );

    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {

            poolExecutor.execute(
                    () -> {
                        Singleton_003 instance = Singleton_003.getInstance();
                        System.out.println(Thread.currentThread().getName() + ":" + instance);
                    }
            );

        }
    }
}
